import Vue from 'vue'
import Router from 'vue-router'
// import axios from '../http'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
// let myActions = []
// axios
//   .get('/api/sysAuth/getCurrentAuthByUser')
//   .then(response => {
//     if (response.data.success === true) {
//       myActions = response.data.result
//       console.log(myActions)
//     }
//   })
//   .catch(error => {
//     console.log(error)
//   })
// console.log(myActions)
// function showMenu(menuids) {
//   console.log(menuids)
//   console.log(myActions)
//   for (const menuid of menuids) {
//     myActions.find(item => item.sysMenuId === menuid)
//     return false
//   }
//   return true
// }
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: '首页',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/info',
    component: Layout,
    name: '信息管理',
    meta: { title: '信息管理', icon: 'form', noCache: true, role: 1 },
    children: [
      {
        path: 'addinfo',
        component: () => import('@/views/info/create'),
        name: 'addinfo',
        meta: { title: '信息刊登', noCache: true }
      },
      {
        path: 'search',
        component: () => import('@/views/info/search'),
        name: '信息查询',
        meta: { title: '信息查询', noCache: true }
      },
      {
        path: 'list',
        component: () => import('@/views/info/list'),
        name: '信息校对',
        meta: { title: '信息校对', noCache: true }
      },
      {
        path: 'collect',
        component: () => import('@/views/info/collect'),
        name: '信息生成',
        meta: { title: '信息生成', noCache: true }
      }
    ]
  },
  // {
  //   path: '/info',
  //   component: Layout,
  //   name: '信息生成',
  //   meta: { role: 2 },
  //   children: [
  //     {
  //       path: 'list',
  //       component: () => import('@/views/wxUser/list'),
  //       name: '信息生成',
  //       meta: { title: '信息生成', icon: 'documentation', noCache: true }
  //     }
  //   ]
  // },
  {
    path: '/wxUser',
    component: Layout,
    name: '微信小程序',
    alwaysShow: true, // will always show the root menu
    meta: { title: '微信小程序', icon: 'wechat', noCache: true, role: 1 },
    children: [
      // {
      //   path: 'list',
      //   component: () => import('@/views/wxUser/list'),
      //   name: '认证审核',
      //   meta: { title: '认证审核' }
      // },
      {
        path: 'bill',
        component: () => import('@/views/bill/list'),
        name: 'bill',
        meta: { title: '账单管理' }
      },
      {
        path: 'billDetail',
        component: () => import('@/views/bill/detail'),
        name: 'billDetail',
        meta: { title: '账单详情' },
        hidden: true
      },
      {
        path: 'online',
        component: () => import('@/views/info/online'),
        name: '在线读报',
        meta: { title: '在线读报' }
      },
      {
        path: 'volpic',
        component: () => import('@/views/info/volpic'),
        name: 'volpic',
        meta: { title: '在线读报广告图片' },
        hidden: true
      },
      // {
      //   path: 'list',
      //   component: () => import('@/views/wxUser/list'),
      //   name: '订单管理',
      //   meta: { title: '订单管理' }
      // },
      {
        path: 'content',
        component: () => import('@/views/content/edit'),
        name: '便民服务',
        meta: { title: '便民服务', noCache: true }
      },
      {
        path: 'advert',
        component: () => import('@/views/advert/list'),
        name: '首页顶部广告',
        meta: { title: '首页顶部广告', noCache: true }
      },
      {
        path: 'slogan',
        component: () => import('@/views/slogan/list'),
        name: '首页底部广告',
        meta: { title: '首页底部广告', noCache: true }
      }
      // {
      //   path: 'message',
      //   component: () => import('@/views/message/list'),
      //   name: '评论管理',
      //   meta: { title: '评论管理' }
      // },
      // {
      //   path: 'chat',
      //   component: () => import('@/views/chat/list'),
      //   name: '聊天管理',
      //   meta: { title: '聊天管理' }
      // }
    ]
  },
  {
    path: '/setting',
    component: Layout,
    name: '系统设置',
    meta: { title: '系统设置', icon: 'component', noCache: true, role: 3 },
    children: [
      {
        path: 'volList',
        component: () => import('@/views/vol/list'),
        name: 'volList',
        meta: { title: '已生成期数', noCache: true },
        hidden: true
      },
      {
        path: 'vol',
        component: () => import('@/views/setting/vol'),
        name: 'settingVol',
        meta: { title: '期数管理', noCache: true }
      }
      // {
      //   path: 'infoClass',
      //   component: () => import('@/views/setting/infoClass'),
      //   name: 'settingInfoClass',
      //   meta: { title: '信息分类', noCache: true }
      // },
      // {
      //   path: 'user',
      //   component: () => import('@/views/setting/user'),
      //   name: 'settingUser',
      //   meta: { title: '管理员管理', noCache: true }
      // }
    ]
  },
  {
    path: '/paper',
    component: Layout,
    name: '报纸开关',
    meta: { role: 3 },
    children: [
      {
        path: '/paper',
        component: () => import('@/views/paper/index'),
        name: '报纸开关',
        meta: { title: '报纸开关', icon: 'el-icon-s-promotion', noCache: true }
      }
    ]
  },
  {
    path: '/price',
    component: Layout,
    name: '收费标准',
    meta: { role: 3 },
    children: [
      {
        path: '/price',
        component: () => import('@/views/price/index'),
        name: '收费标准',
        meta: { title: '收费标准', icon: 'el-icon-s-help', noCache: true }
      }
    ]
  },
  {
    path: '/statistic',
    component: Layout,
    name: '数据统计',
    meta: { role: 3 },
    children: [
      {
        path: '/statistic',
        component: () => import('@/views/statistic/index'),
        name: '数据统计',
        meta: { title: '数据统计', icon: 'el-icon-s-data', noCache: true }
      }
    ]
  },
  {
    path: '/profile',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'password',
        component: () => import('@/views/profile/password'),
        name: '修改密码',
        meta: { title: '修改密码', icon: 'user', noCache: true },
        hidden: true
      }
    ]
  },
  // {
  //   path: '/system',
  //   hidden: true,
  //   component: Layout,
  //   name: '系统管理',
  //   alwaysShow: true, // will always show the root menu
  //   meta: { title: '系统管理', icon: 'tree-table', noCache: true },
  //   children: [
  //     {
  //       path: 'user/reguserlist',
  //       component: () => import('@/views/user/reguserlist'),
  //       name: 'regUserList',
  //       meta: { title: '审批注册用户' },
  //       hidden: true
  //     },
  //     {
  //       path: 'unit',
  //       component: () => import('@/views/sysunit/list'),
  //       name: '单位管理',
  //       meta: { title: '单位管理' }
  //     },
  //     {
  //       path: 'deptment',
  //       component: () => import('@/views/sysdept/list'),
  //       name: '部门管理',
  //       meta: { title: '部门管理' }
  //     },
  //     {
  //       path: 'user',
  //       component: () => import('@/views/user/list'),
  //       name: '用户管理',
  //       meta: { title: '用户管理' }
  //     }
  //     {
  //       path: 'career',
  //       component: () => import('@/views/career/list'),
  //       name: '职业生涯',
  //       meta: { title: '职业生涯' }
  //     }
  //     {
  //       path: 'menu',
  //       component: () => import('@/views/documentation/index'),
  //       name: '菜单管理',
  //       meta: { title: '菜单管理' }
  //     },
  //     {
  //       path: 'auth',
  //       component: () => import('@/views/example/create'),
  //       name: '权限管理',
  //       meta: { title: '权限管理' }
  //     },
  //     {
  //       path: 'role',
  //       component: () => import('@/views/sysrole/list'),
  //       name: '角色管理',
  //       meta: { title: '角色管理' }
  //     },
  //     {
  //       path: 'log',
  //       component: () => import('@/views/documentation/index'),
  //       name: '系统日志',
  //       meta: { title: '系统日志' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

  /** when your routing map is too long, you can split it into small modules **/

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
